import urllib3
import re

# 访问行业板块数据
http = urllib3.PoolManager();

pages = 4
conts = []
for p in range(1, pages + 1):
    url = "http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?cb=jQuery1124012582582823807198_1554554782636&type=CT&token=4f1862fc3b5e77c150a2b985b12db0fd&sty=FPGBKI&js=({data:[(x)],recordsFiltered:(tot)})&cmd=C._BKHY&st=(ChangePercent)&sr=-1&p=%d" % p
    url += "&ps=20&_=1554554783027"
    try:
        resp_dat = http.request('GET', url)
        pattern = re.compile(r'BK(.*?)"')
        bk_list = re.findall(pattern, resp_dat.data.decode())
        for bk in bk_list:
            conts.append(bk)
        print(resp_dat.data.decode())
    except Exception as e:
        print(resp_dat.status)
        print(e)

print(conts)
